package com.atguigu.base;
//可重入锁/递归锁,是指在同一个线程中,外层方法获取锁的时候,再静茹该线程的内层方法会自动获取锁
//java中的Reentrantlock和synchronized都是可重入锁,可重入锁的一个优点是"可一定程度避免死锁"
import java.util.concurrent.locks.ReentrantLock;

public class ReentrantLockDemo {
    public synchronized void a(){
        this.b();
        System.out.println("a");
    }
    public synchronized void b(){
        System.out.println("b");
    }
    private final ReentrantLock lock = new ReentrantLock();
    public final ReentrantLock lock1 = new ReentrantLock();
    public void c(){
        lock.lock();
        try {
            d();
        }finally{
                lock.unlock();
        }
    }
    public void d(){
        lock1.lock();
        try{
            System.out.println("d");
        }finally {lock1.unlock();
    }}
    public static void main(String[] args){ new ReentrantLockDemo().a();}

}
